<?php
/**
 * Created by PhpStorm.
 * User: xiong <1099446868@qq.com>
 * DateTime: 2018/12/22
 * TIME: 1:18
 */

namespace app\mobile\controller;


use think\Controller;
use think\Db;
use think\facade\Request;

class BaseController extends Controller {

    public function __construct() {
        parent::__construct();

        if ($_SERVER['HTTP_HOST'] == 'xiaojuan.fun') {

            $this->redirect("http://www.xiaojuan.fun", 301);
        }

        //$this->isPhone();
        $this->visitor();
    }

    //记录访客浏览记录
    public function visitor() {
        $request = Request::instance();
        //exit($controller .'---'. $action .'----'. $url);
        $ip = get_client_ip();
        //echo $ip;exit;
        if ($ip != '220.112.127.174') {
            $data = [
                'ip'     => $ip,
                'agent'  => getagent(),
                'handle' => $request->controller() . '/' . $request->action(),
                'url'    => $request->url(),
                'time'   => date('Y-m-d H:i:s', time()),
                'isphone'=>2
            ];
            Db::name('visitor')->insert($data);
        }
    }

    public function _empty() {
        //$request = Request::instance();
        //echo $request->controller() . '/' . $request->action();
        return '页面丢失~';
    }
}